package com.slipper.qmt.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RedisSender {
    private static final Logger logger = LoggerFactory.getLogger(RedisSender.class);

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 消息发送
     */
    public void sendMsg(String topic, Object message) {
        try {
            this.stringRedisTemplate.convertAndSend(topic, message);
            logger.info("消息发送，topic[{}], message[{}]", topic, message);
        } catch (Exception e) {
            logger.error("消息发送失败，topic[{}], message[{}]", topic, message, e);
        }
    }
}
